@echo off

set BACKUP_DIR=D:\9cloud\membership\backup
set BACKUP_FILE=%BACKUP_DIR%\membership_backup_%date:~-4,4%%date:~-10,2%%date:~-7,2%_%time:~0,2%%time:~3,2%%time:~6,2%.sql

"C:\Program Files\MySQL\MySQL Server 8.0\bin\mysqldump.exe" -u membership -pNCloud@no-pms46Com membership > %BACKUP_FILE% 

if %ERRORLEVEL% neq 0 (
  echo Error: Backup failed.
  exit /b 1
) else (
  echo Backup successful. File saved to %BACKUP_FILE%
)

set SEVENZIP_PATH=C:\Program Files\7-Zip\7z.exe

"%SEVENZIP_PATH%" a -t7z %BACKUP_FILE%.7z %BACKUP_FILE%

if %ERRORLEVEL% neq 0 (
  echo Error: Compression failed.
  exit /b 1
) else (
  echo Compression successful.
)

del %BACKUP_FILE%

exit /b 0
